package com.woniu.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniu.entity.UserApprove;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author hyl
 * @since 2022-08-28
 */
public interface UserApproveMapper extends BaseMapper<UserApprove> {
    /*/**
     *@description 根据userid查询员工审批
     *@params [userId]
     *@return_value com.woniu.entity.UserApprove
     *@author hyl
     *@date 2022/8/30
     */
    @Select("select * from user_approve,user,user_app_category,dept where user_approve.user_id=${userId} and user_approve.user_id=user.user_id and user_approve.user_app_category_id=user_app_category.user_app_category_id and user_approve.dept_id=dept.dept_id")
    @Results(id = "userApproveMap", value = {
            @Result(column = "dept_id", property = "dept.deptId"),
            @Result(column = "dept_name", property = "dept.deptName"),
            @Result(column = "dept_manager_id", property = "dept.deptManagerId"),
            @Result(column = "dept_status", property = "dept.deptStatus"),
            @Result(column = "user_app_category_id", property = "userAppCategory.userAppCategoryId"),
            @Result(column = "user_app_category_name", property = "userAppCategory.userAppCategoryName"),
            @Result(column = "user_id", property = "user.userId"),
            @Result(column = "user_name", property = "user.userName"),
            @Result(column = "account", property = "user.account"),
    })
    UserApprove getUserAppByUserId(Integer userId);

    /*/**
     *@description 多条件查询userApprove
     *@params [wrapper]
     *@return_value java.util.List<com.woniu.entity.UserApprove>
     *@author hyl
     *@date 2022/8/30
     */
    @Select("select * from user_approve,user,user_app_category,dept ${ew.customSqlSegment} and user_approve.user_id=user.user_id and user_approve.user_app_category_id=user_app_category.user_app_category_id and user_approve.dept_id=dept.dept_id")
    @ResultMap("userApproveMap")
    List<UserApprove> getUserAppByAny(@Param(Constants.WRAPPER) Wrapper<UserApprove> wrapper);

    /*/**
     *@description 多条件分页查询userApprove
     *@params [page, wrapper]
     *@return_value com.baomidou.mybatisplus.extension.plugins.pagination.Page<com.woniu.entity.UserApprove>
     *@author hyl
     *@date 2022/8/30
     */
    @Select("select * from user_approve,user,user_app_category,dept ${ew.customSqlSegment} and user_approve.user_id=user.user_id and user_approve.user_app_category_id=user_app_category.user_app_category_id and user_approve.dept_id=dept.dept_id")
    @ResultMap("userApproveMap")
    Page<UserApprove> getUserAppByAnyWithPage(Page<UserApprove> page, @Param(Constants.WRAPPER) Wrapper<UserApprove> wrapper);
}
